// 1. 初始化状态
const init_state = {
  num: 999,
};
// 2. 导出一个函数，负责处理action和数据
export default (state = init_state, action) => {
  // 数据处理...
  // JSON 方法进行深拷贝
  let newState = JSON.parse(JSON.stringify(state));
  switch (action.type) {
    case "ADD":
      newState.num = state.num + action.payload.num;
      break;
    case "SUB":
      newState.num = state.num + action.payload.num;
      break;
    default:
      return state;
  }
  return newState;
};
